import express, { NextFunction, Response, Request } from 'express';
import { loginRouter } from '../modules/login';
import { registerRouter } from '../modules/register';
import { uploadRouter } from '../modules/upload'
import { userRouter } from '../modules/user'
import { classRouter } from '../modules/class'
import { paperRouter } from '../modules/paper'
import { loadMidd } from './loadMidd';
import { error } from '../utils/resp';
import { Error } from '../common/types/resp';
const app = express();

// 加载中间件
loadMidd(app);

// 使用路由
app.use('/login', loginRouter);
app.use('/register', registerRouter);
app.use('/upload', uploadRouter);
app.use('/user', userRouter)
app.use('/class', classRouter)
app.use('/paper', paperRouter)

/**
 * 错误处理
 */
app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
    // 响应码
    res.statusCode = err.code || 200
    error(res, { msg: err.msg })
})


export default app;
